package dev.alm.springaidemo.controller;

import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("client")
public class ChatClientController {

    @Resource
    private ChatClient chatClient;

//    @GetMapping("chat")
//    public String chat(@RequestParam("message") String message) {
//        return chatClient.prompt().user(message).call().content();
//    }

    @GetMapping(value = "chat", produces = "text/html;charset=utf-8")
    public Flux<String> chat(@RequestParam("message") String message) {
        Flux<String> content = chatClient.prompt().user(message).stream().content();
        return content;
    }

}
